package com.inspur.edp.cef.core.validation.enumvaladaptor;

import com.inspur.edp.cef.api.validation.ICefValidationContext;
import com.inspur.edp.cef.core.i18n.I18nResourceUtil;
import com.inspur.edp.cef.spi.entity.info.EnumValueInfo;
import java.util.List;

public class IntegerEnumValAdaptor extends EnumValAdaptor<Integer>{
    public IntegerEnumValAdaptor(String propName, List<EnumValueInfo> enumValueInfos) {
        super(propName, enumValueInfos);
    }

    @Override
    protected String getDisplayMessage(ICefValidationContext context) {
        //国际化异常调用资源文件
        String exceptionCode = I18nResourceUtil.getResourceItemValue("pfcommon", "cef_exception.properties",
                "Gsp_EnumFieldDisabled_0001");
        return String.format(exceptionCode,this.propName);
    }

    @Override
    protected boolean isValid(Integer value) {
        for(EnumValueInfo valueInfo: enumValueInfos) {
            if(valueInfo.getIndex().equals(value) && valueInfo.getEnumItemDisabled()) {
                return false;
            }
        }
        return true;
    }
}
